<template>
<div class="login-container">

  <div class="login-head">
    <div class="header-wrapper">
      <div class="head-item-logo fl">
        <img src="../../assets/img/mas.png" alt="">
        <!-- <div class="head-logo-title">人才信息库</div> -->
      </div>
      <div class="head-item-title fl">
        <span class="head-title">马鞍山籍大学生人才库</span>
      </div>
      <div class="clear"></div>
    </div>
  </div>

  <div class="login-body">
    <div class="login-box">
      <el-form autoComplete="on" :model="loginForm" :rules="loginRules" ref="loginForm" label-position="left" label-width="0px" class="card-box login-form">
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane label="账号密码登录" name="first">
                <el-form-item prop="username">
                  <el-input name="username" type="text" v-model="loginForm.username" autoComplete="on" placeholder="账户">
                      <i slot="prefix" class="fa fa-user-o"></i>
                  </el-input>
                </el-form-item>
                <el-form-item prop="password">
                  <el-input name="password" type="password" @keyup.enter.native="handleLogin" v-model="loginForm.password" autoComplete="on" placeholder="密码">
                    <i slot="prefix" class="fa fa-key"></i>
                  </el-input>
                </el-form-item>
          </el-tab-pane>
          <!-- <el-tab-pane label="手机号登录" name="second">

                <el-form-item prop="photo">
                  <el-input name="photo" type="text" prefix-icon="el-icon-mobile-phone" v-model="loginForm.photo" autoComplete="on" placeholder="手机号"></el-input>
                </el-form-item>

                <el-form-item prop="authCode">
                  <el-row :gutter="10">
                    <el-col :span="15">
                      <el-input name="authCode" type="text" prefix-icon="el-icon-message" @keyup.enter.native="handleLogin" v-model="loginForm.authCode" autoComplete="on" placeholder="验证码"></el-input>
                    </el-col>
                    <el-col :span="9" class="text-right">
                      <el-button>获取验证码</el-button>
                    </el-col>
                  </el-row>
                </el-form-item>

            </el-tab-pane> -->
        </el-tabs>
        <el-form-item>
          <el-button type="primary" style="width:100%;" :loading="loading" @click.native.prevent="handleLogin">
            登录
          </el-button>
        </el-form-item>
        <div class="login-registry-row text-right">
          <a href="#/find" class="mr10"><span>忘记密码</span></a>
          <a href="#/registry"><span>注册用户</span></a>
        </div>
      </el-form>
    </div>
  </div>

  <div class="login-foot">
    <div class="footer-wrapper">
        <div class="footer-body">
          <div class="footer-link fl">
               <img src="../../assets/img/mas.png" alt="">
                <div>
                    <span>安徽省<b> · </b>马鞍山</span>
                </div>
          </div>
          <div class="footer-copyright fl">
                <p>
                    <span>主办单位：马鞍山市教育局</span>
                </p>
                <!-- <p>
                    <span>运行单位：安徽省人民政府政务服务中心</span>
                </p> -->
                <p id="telephone">
                    <span>联系方式：0555-8324850</span>
                </p>
                <p>
                    <span><a href="http://www.miibeian.gov.cn/" target="_blank">备案序号：皖ICP备0000号</a></span>
                    <span class="public-network-security"><a href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=34011102000822" target="_blank">皖公网安备 34011000000号</a></span>
                </p>
            </div>
            <div class="clearfix"></div>
        </div>
    </div>
  </div>

</div>
</template>

<script>
import socialSign from './socialsignin';

export default {
  components: {
    socialSign
  },
  name: 'login',
  data() {
    // const validatePass = (rule, value, callback) => {
    //   if (value.length < 1) {
    //     callback(new Error('请输入密码'));
    //   } else {
    //     callback();
    //   }
    // };
    return {
      activeName: 'first',
      loginForm: {
        username: '',
        password: '',
        photo: '',
        authCode: ''
      },
      loginRules: {
        username: [{
          required: true,
          message: '账号不能为空',
          trigger: 'blur'
        },
        {
          min: 1,
          max: 20,
          message: '长度在 1 到 20 个字符',
          trigger: 'blur'
        }],
        password: [{
          required: true,
          message: '密码不能为空',
          trigger: 'blur',
          // validator: validatePass
        }],
        photo: [{
          required: true,
          message: '手机号不能为空',
          trigger: 'blur',
          // validator: validatePass
        }],
        authCode: [{
          required: true,
          message: '验证码不能为空',
          trigger: 'blur',
          // validator: validatePass
        }]
      },
      loading: false,
      showDialog: false
    }
  },
  methods: {
    handleClick(tab, event) {
      console.log(tab, event);
    },
    handleLogin() {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.loading = true;
          this.$store.dispatch('LoginByEmail', this.loginForm).then(() => {
            this.loading = false;
            this.$router.push({
              path: '/'
            });
            // this.showDialog = true;
          }).catch(() => {
            this.loading = false;
          });
          // this.$http.post('/oauth/token', {
          //   username: this.loginForm.username,
          //   password: this.loginForm.password
          // }, {
          //   headers: {
          //     Authorization: 'Basic enV1bDp6dXVs'
          //   },
          //   emulateJSON: true,
          //   emulateHTTP: true
          // }).then(function(response) {
          //   if (response.status === 200) {
          //     this.$store.dispatch('LoginByEmail', this.loginForm).then(() => {
          //       this.loading = false;
          //       this.$router.push({
          //         path: '/'
          //       });
          //       // this.showDialog = true;
          //     }).catch(() => {
          //       this.loading = false;
          //     });
          //   } else {
          //     this.loading = false;
          //     return false;
          //   }
          // }, function(error) {
          //   console.log('server error!!');
          //   this.loading = false;
          //   return false;
          // });
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    afterQRScan() {
      // const hash = window.location.hash.slice(1);
      // const hashObj = getQueryObject(hash);
      // const originUrl = window.location.origin;
      // history.replaceState({}, '', originUrl);
      // const codeMap = {
      //   wechat: 'code',
      //   tencent: 'code'
      // };
      // const codeName = hashObj[codeMap[this.auth_type]];
      // if (!codeName) {
      //   alert('第三方登录失败');
      // } else {
      //   this.$store.dispatch('LoginByThirdparty', codeName).then(() => {
      //     this.$router.push({ path: '/' });
      //   });
      // }
    }
  },
  created() {
    // window.addEventListener('hashchange', this.afterQRScan);
  },
  destroyed() {
    // window.removeEventListener('hashchange', this.afterQRScan);
  }
}
</script>

<style rel="stylesheet/scss" lang="scss">
@import "src/styles/mixin.scss";
.tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 5px;
}
.login-main{
    position: absolute;
    top: 50%;
    left: 50%;
    margin-left: -420px;
    margin-top: -200px;
}
/*登陆框样式*/
.login-title-dialog{
    // width: 400px;
    padding: 100px 80px 15px;
    text-align: center;
    .title-icon{
      color: #8398ac;
      i{
        font-size: 48px;
      }
    }
    .title-txt{
      color: #8398ac;
    }
}
.text-right{
  text-align: right;
}

.login-container {
    // background-image: url('../../assets/svg/login-bg.svg');
    background-repeat: no-repeat;
    background-position: center 110px;
    background-size: 100%;

    @include relative;
    height: 100vh;
    background-color: #f0f2f5;
  .login-head{
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      background: linear-gradient(#72a4eb, #ffffff);
      height: 80px;
      .header-wrapper{
        img{
          width: 80px;
        }
      }

    .header-wrapper{
      width: 80%;
      margin: 0 auto;
      height: 80px;
      // line-height: 80px;
      .head-title{
        font-size: 24px;
        font-weight: 600;
        color: #333;
      }
      .head-item-logo{
        text-align: center;
        padding-top: 14px;
        .head-logo-title{
          color: #3e3a39;
          font-size: 12px;
          font-family: jianhei;
          font-weight: 600;
          margin-top: -5px;
        }
      }
      .head-item-title{
        height: 80px;
        line-height: 80px;
        padding: 0 20px;
      }
    }
  }

  .login-body{
    margin-top: 80px;
    background: url(../../assets/img/login-bg5.jpg) no-repeat center center;
    background-size: 100% 100%;
    width: 100%;
    height: 100%;

    .login-box{
      position: absolute;
      background: rgba(255,255,255,0.8);
      padding: 20px 40px;
      top: 25%;
      right: 10%;
      width: 420px;
    }
  }

  .login-foot {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 15px 0;
    background: #275293;
    color: #ccc;
    text-align: center;
    font-size: 14px;
    .footer-body{
      width: 800px;
      margin: 0 auto;
      .footer-copyright{
          text-align: left;
          margin-left: 100px;
      }
    }
    .footer-link{
      img{
        width: 100px;
      }
    }
}

  .login-registry-row{
    a{
      color: #1890ff;
    }
  }

}
</style>
